package com.minshenglife.zanzan.web.manage;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xwpf.usermodel.Borders;
import org.apache.poi.xwpf.usermodel.BreakClear;
import org.apache.poi.xwpf.usermodel.BreakType;
import org.apache.poi.xwpf.usermodel.LineSpacingRule;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.TextAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.minshenglife.commons.dal.Page;
import com.minshenglife.zanzan.entity.ComplainCount;
import com.minshenglife.zanzan.entity.Dept;
import com.minshenglife.zanzan.entity.DeptCount;
import com.minshenglife.zanzan.entity.ManagerMail;
import com.minshenglife.zanzan.entity.ReviewCount;
import com.minshenglife.zanzan.entity.User;
import com.minshenglife.zanzan.entity.UserLog;
import com.minshenglife.zanzan.entity.UserSoft;
import com.minshenglife.zanzan.entity.WorkLogCount;
import com.minshenglife.zanzan.entity.WorkLogCountWeek;
import com.minshenglife.zanzan.entity.power.GroupPower;
import com.minshenglife.zanzan.entity.power.ManagerEmp;
import com.minshenglife.zanzan.pub.utils.Message;
import com.minshenglife.zanzan.result.ManagerResult;
import com.minshenglife.zanzan.service.GroupPowerService;
import com.minshenglife.zanzan.service.UserService;
import com.minshenglife.zanzan.service.UserSoftService;
import com.minshenglife.zanzan.service.WorkConMarketPowerService;
import com.minshenglife.zanzan.service.WorkConPowerService;
import com.minshenglife.zanzan.service.manage.ManagerService;
import com.minshenglife.zanzan.service.power.ManagerEmpService;
import com.minshenglife.zanzan.web.manage.cst.ManageKeys;
import com.minshenglife.zanzan.web.manage.vo.ExportDataVo;
import com.minshenglife.zanzan.web.manage.vo.LogVo;
import com.minshenglife.zanzan.web.manage.vo.ManagerBaseVo;
import com.minshenglife.zanzan.web.manage.vo.ManagerVo;
import com.minshenglife.zanzan.web.manage.vo.ReviewVo;
import com.nationsky.pub.utils.StringUtils;

/**
 * @author Hao HaiLin
 *
 */

@Controller
@RequestMapping("/managers")
public class ManagerController {
	Logger log = LoggerFactory.getLogger(ManagerController.class);
	/**可以被审阅的用户*/
	private final String CANBEREVIEWUSER="NC_CanBeReviewUser"; 
	
	@Resource 
	UserService userService;
	@Resource
	ManagerService managerService;
	@Resource
	WorkConPowerService workConPowerService; 
	@Resource
	ManagerEmpService managerEmpService;
	@Resource
	WorkConMarketPowerService workConMarketPowerService;
	@Resource
	UserSoftService userSoftService;
	@Resource
	GroupPowerService groupPowerService;
	
	private int excelCellIndex = 0;
	
	@RequestMapping(value="/login.mge",method=RequestMethod.POST)
	public String managerLogin(User user,ModelMap modeMap,@RequestParam String code,
			HttpServletRequest request, HttpServletResponse response) throws IOException{
		boolean isManager = true;
		String forwardUrl = "/manage/login";
		HttpSession session = request.getSession();
		session.setMaxInactiveInterval(20*60);//有效期20分钟
		System.out.println("yanzhengma code---->" + code);
		//验证验证码 add by jianghaibo 2015-09-18
		String sccode = (String) session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
		System.out.println("session code --- > " + sccode);
		if(code == null || !code.equals(sccode)){//验证码错误
			modeMap.addAttribute("error", "验证码错误！");
			return forwardUrl;
		}
		//微家后台登陆
		List<User> list;
		System.out.println(toMD5("zz_admin"));
		System.out.println(user.getEmp_name());
		list = managerService.getUser(user.getEmp_name(), toMD5(user.getPassword()));
//		list = managerService.getUser(user.getEmp_name(), "96e79218965eb72c92a549dd5a330112");
		if(!list.isEmpty() && list.size()>0 
				&& list.get(0).getEmp_name().equals("zzmsr")){
			session.setAttribute(ManageKeys.SESSION_USER_KEY, list.get(0));
			User user1 = (User)session.getAttribute(ManageKeys.SESSION_USER_KEY);
			modeMap.addAttribute("loginUser", user1);
			//response.sendRedirect(Config.getProperty(Config.WX_BASEURL)+"/jsp/manage/countByTime.jsp");//"redirect:/jsp/manage/countByTime";
//			return "/jsp/manage/countByTime";
			forwardUrl = "/jsp/manage/countByTime";
			isManager = true;
		}else{
//			modeMap.addAttribute("error", "用户名或密码错误，请重新输入！");
//			return "/manage/login";
			isManager = false;
		}
		
		//新日志权限登陆  add by jianghaibo 2015-06-29
		ManagerEmp managerEmp = managerEmpService.findMangerEmp(user.getEmp_name(), user.getPassword());
		if (managerEmp != null && managerEmp.getEmpId() != null) {
			session.setAttribute("managerEmp", managerEmp);
			ManagerEmp manager = (ManagerEmp) session.getAttribute("managerEmp");
			modeMap.addAttribute("loginUser", manager);
			forwardUrl = "/jsp/power/main";
			isManager = true;
		} else {
			isManager = false;
		}
		if(!isManager){
			modeMap.addAttribute("error", "用户名或密码错误，请重新输入！");
		}
		//删除验证码session
		session.removeAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
		return forwardUrl;
	}
	@RequestMapping(value="/logOut.mge",method=RequestMethod.GET)
	public String managerLogOut(HttpServletRequest request){
		log.info("start   managerLogOut() ");
		try{
//			request.getSession(true).invalidate();
			request.getSession(true).removeAttribute(ManageKeys.SESSION_USER_KEY);
		}catch(Exception e){
			e.printStackTrace();
			log.info("用户注销异常");
			return "/jsp/manage/error";
		}
		log.info("end   managerLogOut() ");
		return "/manage/login";
	}
	
//	@RequestMapping(value="/test.mge")
	public String test(HttpServletRequest request){
		log.info("start   test() ");
		try{
			String sccode = (String) request.getSession(true).getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
			String sessionid = request.getSession(true).getId();
			System.out.println("session_id --> "+sessionid);
			log.info("session yanzhengma code --> " + sccode);
			Cookie[] cookies = request.getCookies();
			for (Cookie cookie : cookies) {
				System.out.println(cookie.getName() + " : " + cookie.getValue());
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		log.info("end   test() ");
		return "/jsp/test";
	}
	
	private String toMD5(String password){
		// md5 encrypt
		MessageDigest md5;
		StringBuffer md5StrBuff = new StringBuffer();
		try {
			md5 = MessageDigest
					.getInstance("MD5");
			md5.update(password.getBytes());
			byte[] domain = md5.digest();
			// converting domain to String
			for (int i = 0; i < domain.length; i++) {
				if (Integer.toHexString(0xFF & domain[i]).length() == 1) {
					md5StrBuff.append("0").append(
							Integer.toHexString(0xFF & domain[i]));
				} else
					md5StrBuff.append(Integer.toHexString(0xFF & domain[i]));
			}
			System.out.println(md5StrBuff.toString());
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return md5StrBuff.toString();
	}
	@RequestMapping(value="/redFlowerCount.mge",method=RequestMethod.POST)
	public String redFlowerCount(ManagerVo managerVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   redFlowerCount() ");
		try {
			Page<User> ret;
			Map<String, Object> map = new HashMap<String, Object>();
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?10:managerBaseVo.getPageSize();
			//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			//Date firstDate = null;
			//Date secondDate = null;
			//if(!"".equals(managerVo.getStartDate())){
			//	firstDate = sdf.parse(managerVo.getStartDate());
			//}
			//if(!"".equals(managerVo.getEndDate())){
			//	secondDate = sdf.parse(managerVo.getEndDate());
			//}
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
			//map.put("startDate", firstDate);
			//map.put("endDate", secondDate);
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			map.put("countFlag", managerVo.getCountFlag());
			ret = managerService.countAll(map, pageNo, pageSize);
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("managerVo", managerVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}
		log.info("end   redFlowerCount() ");
		return "/jsp/manage/countResult";
	}
	@RequestMapping(value="/exportData.mge",method=RequestMethod.POST)
	public String exportData(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response){
		log.info("start   exportData() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
			//map.put("startDate", managerVo.getStartDate());
			//map.put("endDate", managerVo.getEndDate());
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			map.put("countFlag", managerVo.getCountFlag());
			List<DeptCount> list = managerService.countByDept(map);
			if(exportDataVo.getExportType().equals("excel")){
				response.setContentType("application/vnd.ms-excel");
				List<User> listExcel = managerService.countForExcel(map);
				try{
				
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(("民生保险微家统计.xls").getBytes("GBK"),"ISO-8859-1"));
				}catch(UnsupportedEncodingException e){
					e.printStackTrace();	
				}
				try{
					OutputStream out = response.getOutputStream();
					System.out.println(listExcel.size());
					managerService.getExcel(map,listExcel,out);
					out.flush();
					out.close();
				}catch(IOException e){
					e.printStackTrace();
				}
				log.info("end   exportData() ");
				return "/jsp/manage/exportExcel";
			}else{
				String imageUrl = managerService.getImageUrl(list, session,request);
				modeMap.addAttribute("imageUrl", imageUrl);
				log.info("end   exportData() ");
				return "/jsp/manage/exportView";
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.info("end   exportData()  errror");
			return "/jsp/manage/error";
		}		
		
	}
	@RequestMapping(value="/userLogCount.mge",method=RequestMethod.POST)
	public String userLogCount(LogVo logVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   userLogCount() ");
		try {
			Page<UserLog> ret;
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?6:managerBaseVo.getPageSize();
			Map<String,Object> map = new HashMap<String, Object>();
			/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date firstDate = null;
			Date secondDate = null;
			if(!"".equals(logVo.getStartDate())){
				firstDate = sdf.parse(logVo.getStartDate());
			}
			if(!"".equals(logVo.getEndDate())){
				secondDate = sdf.parse(logVo.getEndDate());
			}*/
			map.put("dept", logVo.getDept());
			map.put("startDate",logVo.getStartDate());
			map.put("endDate", logVo.getEndDate());
			map.put("emp_name", logVo.getEmp_name());
			ret = managerService.countForLog(map, pageNo, pageSize);
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("logVo",logVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   userLogCount() ");
		}
		return "/jsp/manage/logCountResult";
	}
	@RequestMapping(value="/loadDept.mge",method=RequestMethod.POST)
	@ResponseBody
	public String loadDept(ModelMap modeMap,HttpServletRequest request) {
		Object attribute = request.getSession().getAttribute(ManageKeys.SESSION_USER_KEY);
		log.debug("session user======="+attribute);
		log.info("start   loadDept() ");
		JSONObject jsonObject = new JSONObject();
		String deptResult ="";
		try {
			List<Dept> list = managerService.findDept();
			modeMap.addAttribute("list", list);
			
			jsonObject.put("data", list);
			jsonObject.put("state", "200");
			deptResult = jsonObject.toString();
			
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("state", "201");
			deptResult = jsonObject.toString();
		}
		log.info("end   loadDept() ");
		return deptResult;
	}
	@RequestMapping(value="/redCountByTime.mge",method=RequestMethod.POST)
	public String redCountByTime(ManagerVo managerVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   redCountByTime() ");
		try {
			Page<User> ret;
			Map<String, Object> map = new HashMap<String, Object>();
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?10:managerBaseVo.getPageSize();
			//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			//Date firstDate = null;
			//Date secondDate = null;
			//if(!"".equals(managerVo.getStartDate())){
			//	firstDate = sdf.parse(managerVo.getStartDate());
			//}
			//if(!"".equals(managerVo.getEndDate())){
			//	secondDate = sdf.parse(managerVo.getEndDate());
			//}
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
     		map.put("startDate", managerVo.getStartDate());
			map.put("endDate", managerVo.getEndDate());
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			//map.put("countFlag", managerVo.getCountFlag());
			ret = managerService.countRed(map, pageNo, pageSize);
			List<User> listRet = ret.getRows();
			for(int i=0;i<listRet.size();i++){
				User userRet = listRet.get(i);
				log.debug(userRet.getEmp_name());
				userRet.setRedFlowerNum(Math.floor(userRet.getRedFlowerNum()));
			}
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("managerVo", managerVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   redCountByTime() ");
		}
		return "/jsp/manage/countRedResult";
	}
	@RequestMapping(value="/exportRedData.mge",method=RequestMethod.POST)
	public String exportRedData(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws ParseException{
		log.info("start   exportRedData() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date firstDate = null;
			Date secondDate = null;
			if(!"".equals(managerVo.getStartDate())){
				firstDate = sdf.parse(managerVo.getStartDate());
			}
			if(!"".equals(managerVo.getEndDate())){
				secondDate = sdf.parse(managerVo.getEndDate());
			}
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
			map.put("startDate", firstDate);
			map.put("endDate", secondDate);
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			//map.put("countFlag", managerVo.getCountFlag());
			//List<DeptCount> list = managerService.countByDept(map);
			if(exportDataVo.getExportType().equals("excel")){
				response.setContentType("application/vnd.ms-excel");
				List<User> listExcel = managerService.countRedForExcel(map);
				for(int i=0;i<listExcel.size();i++){
					listExcel.get(i).setRedFlowerNum(Math.floor(listExcel.get(i).getRedFlowerNum()));
				}
				try{
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(("民生保险微家统计.xls").getBytes("GBK"),"ISO-8859-1"));
				}catch(UnsupportedEncodingException e){
					e.printStackTrace();	
				}
				try{
					OutputStream out = response.getOutputStream();
					System.out.println(listExcel.size());
					managerService.getRedExcel(map,listExcel,out);
					out.flush();
					out.close();
				}catch(IOException e){
					e.printStackTrace();
				}
				
				return "/jsp/manage/exportExcel";
			}else{
//			String imageUrl = managerService.getImageUrl(list, session,request);
//			modeMap.addAttribute("imageUrl", imageUrl);
				return "/jsp/manage/exportView";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   exportRedData() ");
		}
		
	}
	@RequestMapping(value="/sendCountByTime.mge",method=RequestMethod.POST)
	public String sendCountByTime(ManagerVo managerVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   sendCountByTime() ");
		try {
			Page<User> ret;
			Map<String, Object> map = new HashMap<String, Object>();
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?10:managerBaseVo.getPageSize();
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
     		map.put("startDate", managerVo.getStartDate());
			map.put("endDate", managerVo.getEndDate());
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			ret = managerService.countSend(map, pageNo, pageSize);
			List<User> listRet = ret.getRows();
			for(int i=0;i<listRet.size();i++){
				User userRet = listRet.get(i);
				log.debug(userRet.getEmp_name());
				Double sendFlowerNum = Math.floor(userRet.getSendFlowerNum().doubleValue());
				userRet.setSendFlowerNum(sendFlowerNum.longValue());
			}
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("managerVo", managerVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   sendCountByTime() ");
		}
		return "/jsp/manage/countSendResult";
	}
	@RequestMapping(value="/exportSendData.mge",method=RequestMethod.POST)
	public String exportSendData(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws ParseException{
		log.info("start   exportSendData() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date firstDate = null;
			Date secondDate = null;
			if(!"".equals(managerVo.getStartDate())){
				firstDate = sdf.parse(managerVo.getStartDate());
			}
			if(!"".equals(managerVo.getEndDate())){
				secondDate = sdf.parse(managerVo.getEndDate());
			}
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
			map.put("startDate", firstDate);
			map.put("endDate", secondDate);
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			//map.put("countFlag", managerVo.getCountFlag());
			//List<DeptCount> list = managerService.countByDept(map);
			if(exportDataVo.getExportType().equals("excel")){
				response.setContentType("application/vnd.ms-excel");
				List<User> listExcel = managerService.countSendForExcel(map);
				for(int i=0;i<listExcel.size();i++){
					Double sendFlowerNum = Math.floor(listExcel.get(i).getSendFlowerNum());
					listExcel.get(i).setSendFlowerNum(sendFlowerNum.longValue());
				}
				try{
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(("民生保险微家统计.xls").getBytes("GBK"),"ISO-8859-1"));
				}catch(UnsupportedEncodingException e){
					e.printStackTrace();	
				}
				try{
					OutputStream out = response.getOutputStream();
					System.out.println(listExcel.size());
					managerService.getSendExcel(map,listExcel,out);
					out.flush();
					out.close();
				}catch(IOException e){
					e.printStackTrace();
				}
				
				return "/jsp/manage/exportExcel";
			}else{
//			String imageUrl = managerService.getImageUrl(list, session,request);
//			modeMap.addAttribute("imageUrl", imageUrl);
				return "/jsp/manage/exportView";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   exportSendData() ");
		}
		
	}
	@RequestMapping(value="/integralCountByTime.mge",method=RequestMethod.POST)
	public String integralCountByTime(ManagerVo managerVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   integralCountByTime() ");
		try {
			Page<User> ret;
			Map<String, Object> map = new HashMap<String, Object>();
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?10:managerBaseVo.getPageSize();
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
     		map.put("startDate", managerVo.getStartDate());
			map.put("endDate", managerVo.getEndDate());
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			ret = managerService.countIntegral(map, pageNo, pageSize);
			List<User> listRet = ret.getRows();
			for(int i=0;i<listRet.size();i++){
				User userRet = listRet.get(i);
				log.debug(userRet.getEmp_name());
				Double integralNum = Math.floor(userRet.getIntegralNum().doubleValue());
				userRet.setIntegralNum(integralNum.longValue());
			}
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("managerVo", managerVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   integralCountByTime() ");
		}
		return "/jsp/manage/countIntegralResult";
	}
	@RequestMapping(value="/exportIntegralData.mge",method=RequestMethod.POST)
	public String exportIntegralData(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws ParseException{
		log.info("start   exportIntegralData() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date firstDate = null;
			Date secondDate = null;
			if(!"".equals(managerVo.getStartDate())){
				firstDate = sdf.parse(managerVo.getStartDate());
			}
			if(!"".equals(managerVo.getEndDate())){
				secondDate = sdf.parse(managerVo.getEndDate());
			}
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
			map.put("startDate", firstDate);
			map.put("endDate", secondDate);
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			//map.put("countFlag", managerVo.getCountFlag());
			//List<DeptCount> list = managerService.countByDept(map);
			if(exportDataVo.getExportType().equals("excel")){
				response.setContentType("application/vnd.ms-excel");
				List<User> listExcel = managerService.countIntegralForExcel(map);
				for(int i=0;i<listExcel.size();i++){
					Double integralFlowerNum = Math.floor(listExcel.get(i).getIntegralNum());
					listExcel.get(i).setIntegralNum(integralFlowerNum.longValue());
				}
				try{
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(("民生保险微家统计.xls").getBytes("GBK"),"ISO-8859-1"));
				}catch(UnsupportedEncodingException e){
					e.printStackTrace();	
				}
				try{
					OutputStream out = response.getOutputStream();
					System.out.println(listExcel.size());
					managerService.getIntegralExcel(map,listExcel,out);
					out.flush();
					out.close();
				}catch(IOException e){
					e.printStackTrace();
				}
				
				return "/jsp/manage/exportExcel";
			}else{
//			String imageUrl = managerService.getImageUrl(list, session,request);
//			modeMap.addAttribute("imageUrl", imageUrl);
				return "/jsp/manage/exportView";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   exportIntegralData() ");
		}
		
	}
	
	@RequestMapping(value="/progressCount.mge",method=RequestMethod.POST)
    public String progressCount(HttpServletRequest request, HttpServletResponse response, ManagerVo managerVo,ManagerBaseVo managerBaseVo,ModelMap modeMap){
		try {
			Page<ManagerResult> ret;
			int pageNo=managerBaseVo.getPageNo()==0? 1: managerBaseVo.getPageNo();
			int pageSize=managerBaseVo.getPageSize()==0? 10: managerBaseVo.getPageSize();
			Map<String,Object> map=new HashMap<String,Object>();
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			ret = managerService.findProgressRank(map, pageNo, pageSize); //进步榜
			modeMap.addAttribute("ret", ret);
		} catch (Exception e) {
			e.printStackTrace();
		}
    	 return "/jsp/manage/countProgressResult";
    }
	@RequestMapping(value="/exportProgressData.mge",method=RequestMethod.POST)
	public String exportProgressData(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws ParseException{
		log.info("start   exportProgressData() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("order", managerVo.getOrder());
			map.put("dept", managerVo.getDept());
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			//map.put("countFlag", managerVo.getCountFlag());
			//List<DeptCount> list = managerService.countByDept(map);
			if(exportDataVo.getExportType().equals("excel")){
				response.setContentType("application/vnd.ms-excel");
				List<ManagerResult> listExcel = managerService.countProgressForExcel(map);
				try{
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(("民生保险微家统计.xls").getBytes("GBK"),"ISO-8859-1"));
				}catch(UnsupportedEncodingException e){
					e.printStackTrace();	
				}
				try{
					OutputStream out = response.getOutputStream();
					System.out.println(listExcel.size());
					managerService.getProgressExcel(map,listExcel,out);
					out.flush();
					out.close();
				}catch(IOException e){
					e.printStackTrace();
				}
				
				return "/jsp/manage/exportExcel";
			}else{
//			String imageUrl = managerService.getImageUrl(list, session,request);
//			modeMap.addAttribute("imageUrl", imageUrl);
				return "/jsp/manage/exportView";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   exportProgressData() ");
		}
	}
	@RequestMapping(value="/countMail.mge",method=RequestMethod.GET)
	public String countMail(HttpServletRequest request, HttpServletResponse response,ManagerBaseVo managerBaseVo,ModelMap modeMap){
		log.info("start   countMail() ");
		try {
			Page<ManagerMail> ret;
			Map<String, Object> map = new HashMap<String, Object>();
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?10:managerBaseVo.getPageSize();
			ret = managerService.findMail(map, pageNo, pageSize);
			modeMap.addAttribute("ret", ret);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   countMail() ");
		}
		return "/jsp/manage/managerMailResult";
	}
	@RequestMapping(value="/{id}/showMailContent.mge",method=RequestMethod.GET)
	public String showMailContent(@PathVariable String id,HttpServletRequest request, HttpServletResponse response,ModelMap modeMap){
		log.info("start   showMailContent() ");
		try {
			ManagerMail managerMailContent;
			Map<String, Object> map = new HashMap<String, Object>();
			System.out.println(id);
			map.put("id",id);
			managerMailContent = managerService.findMailContent(map);
			modeMap.addAttribute("managerMailContent", managerMailContent);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   showMailContent() ");
		}
		return "/jsp/manage/showMailContent";
		
	}
	@RequestMapping(value="/reviewCount.mge",method=RequestMethod.POST)
	public String reviewCount(ReviewVo reviewVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   reviewCount() ");
		try {
			Page<ReviewCount> ret;
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?10:managerBaseVo.getPageSize();
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("empId",reviewVo.getEmpId());
			map.put("startDate",reviewVo.getStartDate());
			map.put("endDate", reviewVo.getEndDate());
			map.put("emp_name", reviewVo.getEmp_name());
			ret = managerService.countReview(map, pageNo, pageSize);
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("reviewVo",reviewVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   reviewCount() ");
		}
		return "/jsp/manage/reviewCountResult";
	}
	@RequestMapping(value="/complainCount.mge",method=RequestMethod.POST)
	public String complainCount(ReviewVo reviewVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   complainCount() ");
		try {
			Page<ComplainCount> ret;
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?10:managerBaseVo.getPageSize();
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("empId",reviewVo.getEmpId());
			map.put("startDate",reviewVo.getStartDate());
			map.put("endDate", reviewVo.getEndDate());
			map.put("emp_name", reviewVo.getEmp_name());
			ret = managerService.countComplain(map, pageNo, pageSize);
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("reviewVo",reviewVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   complainCount() ");
		}
		return "/jsp/manage/complainCountResult";
	}
	@RequestMapping(value="/workLogCountByWeek.mge",method=RequestMethod.POST)
	public String workLogCountByWeek(ReviewVo reviewVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   workLogCount() ");
		try {
			Page<WorkLogCountWeek> ret = null;
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?5:managerBaseVo.getPageSize();
			Map<String,Object> map = new HashMap<String, Object>();
			//String canBeReviewUser=Config.getProperty(CANBEREVIEWUSER);
			//add by jianghaibo 2015-02-04  获取可以被审阅人员列表
			String canBeReviewUser = "";
			if("1".equals(reviewVo.getLogType())){
				canBeReviewUser = workConPowerService.findPowerUserByType(CANBEREVIEWUSER);
				map.put("logType", reviewVo.getLogType());
			}else if("3".equals(reviewVo.getLogType())){
				canBeReviewUser = workConMarketPowerService.findCanBeReviewUser();
				map.put("logType", "1");
				map.put("postId", "A");
			}else if("4".equals(reviewVo.getLogType())){
				map.put("logType", reviewVo.getLogType());
				map.put("postId", "B");
			}else{
				map.put("logType", reviewVo.getLogType());
			}
			
			log.info("canBeReviewUser --> "+canBeReviewUser);
			map.put("empId",reviewVo.getEmpId());
			map.put("emp_name", reviewVo.getEmp_name());
			
//			if(!reviewVo.getLogDate().isEmpty()&&reviewVo.getLogDate().trim()!=""){//日志时间
				map.put("logDate", reviewVo.getLogDate());
				map.put("canBeReviewUser", canBeReviewUser);
				
//				ret = managerService.countWorkLogBySHY(map, pageNo, pageSize);
				
//			}else{ //开始 结束 时间
				map.put("startDate",reviewVo.getStartDate());
				
				map.put("weekday0",reviewVo.getStartDate());				
				Date date = (new SimpleDateFormat("yyyy-MM-dd")).parse(reviewVo.getStartDate());
				Calendar cal = Calendar.getInstance();
				cal.setTime(date);
				cal.add(Calendar.DATE, 1);
				map.put("weekday1",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
				cal.add(Calendar.DATE, 1);
				map.put("weekday2",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
				cal.add(Calendar.DATE, 1);
				map.put("weekday3",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
				cal.add(Calendar.DATE, 1);
				map.put("weekday4",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
				cal.add(Calendar.DATE, 1);
				map.put("weekday5",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
				cal.add(Calendar.DATE, 1);
				map.put("weekday6",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));			
				map.put("endDate", (new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
				
				if("4".equals(reviewVo.getLogType())||"1".equals(reviewVo.getLogType())){
					ret = managerService.countBWeekWorkLog(map, pageNo, pageSize);
				}else{
					//ret = managerService.countWorkLog(map, pageNo, pageSize);
				}	
				log.info("canBeReviewUser --> "+canBeReviewUser);
				log.info("ret.getRows().size()"+ret.getRows().size());
				System.out.println("ret.getRows().size()dfsfddg"+ret.getRows().size());
				for(int j=0;j<ret.getRows().size();j++){
					int countn=0;
					if(!ret.getRows().get(j).getWeekday0().equals("0")){
						ret.getRows().get(j).setWeekday0("√");
						countn++;
						
					}else{
						ret.getRows().get(j).setWeekday0("");
					}
					if(!ret.getRows().get(j).getWeekday1().equals("0")){						
						countn++;
						ret.getRows().get(j).setWeekday1("√");
					}else{
						ret.getRows().get(j).setWeekday1("");
					}
						
					if(!ret.getRows().get(j).getWeekday2().equals("0")){
						countn++;
						ret.getRows().get(j).setWeekday2("√");
					}else{
						ret.getRows().get(j).setWeekday2("");
					}
					if(!ret.getRows().get(j).getWeekday3().equals("0")){
						countn++;
						ret.getRows().get(j).setWeekday3("√");
					}else{
						ret.getRows().get(j).setWeekday3("");
					}
					if(!ret.getRows().get(j).getWeekday4().equals("0")){
						countn++;
						ret.getRows().get(j).setWeekday4("√");
					}else{
						ret.getRows().get(j).setWeekday4("");
					}
					if(!ret.getRows().get(j).getWeekday5().equals("0")){
						countn++;
						ret.getRows().get(j).setWeekday5("√");
					}else{
						ret.getRows().get(j).setWeekday5("");
					}
					if(!ret.getRows().get(j).getWeekday6().equals("0")){
						countn++;
						ret.getRows().get(j).setWeekday6("√");
					}else{
						ret.getRows().get(j).setWeekday6("");
					}
					ret.getRows().get(j).setCount(countn+"");
					log.info("countn"+ret.getRows().get(j).getCount());
				}
							
			
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("reviewVo",reviewVo);
			modeMap.addAttribute("map",map);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   workLogCount() ");
		}
		return "/jsp/manage/workLogCountByWeekResult";
	}
	
	@RequestMapping(value="/exportWorkLogDataWeeky.mge",method=RequestMethod.POST)
	public String exportWorkLogDataWeeky(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws ParseException{
		log.info("start   exportWorkLog() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//			SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");//日志时间查询
			
			String logDate_obj=null;
			//String canBeReviewUser=Config.getProperty(CANBEREVIEWUSER);
			//add by jianghaibo 2015-02-04  获取一把手日志可被审阅人列表
			 String canBeReviewUser ="";
			if("1".equals(managerVo.getLogType())||"2".equals(managerVo.getLogType())||"3".equals(managerVo.getLogType())){ //
			   canBeReviewUser = workConPowerService.findPowerUserByType(CANBEREVIEWUSER);
			}
			if(!"".equals(managerVo.getLogDate())){
				logDate_obj=managerVo.getLogDate();
			}
		
			map.put("startDate",managerVo.getStartDate());			
			map.put("weekday0",managerVo.getStartDate());				
			Date date = (new SimpleDateFormat("yyyy-MM-dd")).parse(managerVo.getStartDate());
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			cal.add(Calendar.DATE, 1);
			map.put("weekday1",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
			cal.add(Calendar.DATE, 1);
			map.put("weekday2",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
			cal.add(Calendar.DATE, 1);
			map.put("weekday3",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
			cal.add(Calendar.DATE, 1);
			map.put("weekday4",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
			cal.add(Calendar.DATE, 1);
			map.put("weekday5",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));
			cal.add(Calendar.DATE, 1);
			map.put("weekday6",(new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));			
			map.put("endDate", (new SimpleDateFormat("yyyy-MM-dd")).format(cal.getTime()));						
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			map.put("logDate", logDate_obj);
			map.put("logType", managerVo.getLogType());
			map.put("canBeReviewUser", canBeReviewUser);
			//map.put("countFlag", managerVo.getCountFlag());
			//List<DeptCount> list = managerService.countByDept(map);
			if(exportDataVo.getExportType().equals("excel")){
				response.setContentType("application/vnd.ms-excel");
				
				List<WorkLogCountWeek> listExcel = null;
				
				if("1".equals(managerVo.getLogType())){ //按日志时间 查询
					map.put("postId", "A");
					
					//listExcel= managerService.countWorkLogBySHYForExcel(map);
				}else if("2".equals(managerVo.getLogType())){
					//listExcel= managerService.countWorkLogForExcel(map);
				}
				else if("3".equals(managerVo.getLogType())){
					//String marketCanBeReviewUser = workConMarketPowerService.findCanBeReviewUser();
					//map.put("canBeReviewUser", marketCanBeReviewUser);
					//map.put("logType", "1");
					//listExcel= managerService.countWorkLogBySHYForExcel(map);
				}else if("4".equals(managerVo.getLogType())){
					map.put("postId", "B");
				}
				if(map.get("postId").equals("A")||map.get("postId").equals("B")){
					listExcel= managerService.countBWorkLogByWeekForExcel(map);
					for(int j=0;j<listExcel.size();j++){
						int countn=0;
						if(!listExcel.get(j).getWeekday0().equals("0")){
							listExcel.get(j).setWeekday0("√");
							countn++;
							
						}else{
							listExcel.get(j).setWeekday0("");
						}
						if(!listExcel.get(j).getWeekday1().equals("0")){						
							countn++;
							listExcel.get(j).setWeekday1("√");
						}else{
							listExcel.get(j).setWeekday1("");
						}
							
						if(!listExcel.get(j).getWeekday2().equals("0")){
							countn++;
							listExcel.get(j).setWeekday2("√");
						}else{
							listExcel.get(j).setWeekday2("");
						}
						if(!listExcel.get(j).getWeekday3().equals("0")){
							countn++;
							listExcel.get(j).setWeekday3("√");
						}else{
							listExcel.get(j).setWeekday3("");
						}
						if(!listExcel.get(j).getWeekday4().equals("0")){
							countn++;
							listExcel.get(j).setWeekday4("√");
						}else{
							listExcel.get(j).setWeekday4("");
						}
						if(!listExcel.get(j).getWeekday5().equals("0")){
							countn++;
							listExcel.get(j).setWeekday5("√");
						}else{
							listExcel.get(j).setWeekday5("");
						}
						if(!listExcel.get(j).getWeekday6().equals("0")){
							countn++;
							listExcel.get(j).setWeekday6("√");
						}else{
							listExcel.get(j).setWeekday6("");
						}
						listExcel.get(j).setCount(countn+"");
						log.info("countn"+listExcel.get(j).getCount());
					}
								
				}
			
		
			
				System.out.println(listExcel.size());
				
				try{
					String fileName="民生保险微家统计.xls";
					SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd");
					String exportDate = sdfs.format(new Date());
					if(managerVo.getLogType().trim().equals("4")){
						
						fileName="民生保险微家B类经理周统计"+exportDate+".xls";
					}else if(managerVo.getLogType().trim().equals("1")){
						
						fileName="民生保险微家A类干部周统计"+exportDate+".xls";
					}
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(fileName.getBytes("GBK"),"ISO-8859-1"));
				}catch(UnsupportedEncodingException e){
					e.printStackTrace();	
				}
				try{
					OutputStream out = response.getOutputStream();
					System.out.println(listExcel.size());
					managerService.getWorkLogWeekExcel(map,listExcel,out);
					out.flush();
					out.close();
				}catch(IOException e){
					e.printStackTrace();
				}
				
				return "/jsp/manage/exportExcel";
			}else{
//			String imageUrl = managerService.getImageUrl(list, session,request);
//			modeMap.addAttribute("imageUrl", imageUrl);
				return "/jsp/manage/exportView";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   exportWorkLog() ");
		}
		
	}
	
	@RequestMapping(value="/workLogCount.mge",method=RequestMethod.POST)
	public String workLogCount(ReviewVo reviewVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   workLogCount() ");
		try {
			Page<WorkLogCount> ret;
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?5:managerBaseVo.getPageSize();
			Map<String,Object> map = new HashMap<String, Object>();
			//String canBeReviewUser=Config.getProperty(CANBEREVIEWUSER);
			//add by jianghaibo 2015-02-04  获取可以被审阅人员列表
			String canBeReviewUser = "";
			if("1".equals(reviewVo.getLogType())){
				canBeReviewUser = workConPowerService.findPowerUserByType(CANBEREVIEWUSER);
				map.put("logType", reviewVo.getLogType());
				map.put("postId", "A");
			}else if("3".equals(reviewVo.getLogType())){
				canBeReviewUser = workConMarketPowerService.findCanBeReviewUser();
				map.put("logType", "1");				
			}else if("4".equals(reviewVo.getLogType())){
				map.put("logType", reviewVo.getLogType());
				map.put("postId", "B");
			}else{
				map.put("logType", reviewVo.getLogType());
			}
			
			log.info("canBeReviewUser --> "+canBeReviewUser);
			map.put("empId",reviewVo.getEmpId());
			map.put("emp_name", reviewVo.getEmp_name());
			
//			if(!reviewVo.getLogDate().isEmpty()&&reviewVo.getLogDate().trim()!=""){//日志时间
				map.put("logDate", reviewVo.getLogDate());
				map.put("canBeReviewUser", canBeReviewUser);
				
//				ret = managerService.countWorkLogBySHY(map, pageNo, pageSize);
				
//			}else{ //开始 结束 时间
				map.put("startDate",reviewVo.getStartDate());
				map.put("endDate", reviewVo.getEndDate());
				if("4".equals(reviewVo.getLogType())||"A".equals(map.get("postId"))){
					ret = managerService.countBWorkLog(map, pageNo, pageSize);
				}else{
					ret = managerService.countWorkLog(map, pageNo, pageSize);
				}				
//			}
			
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("reviewVo",reviewVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   workLogCount() ");
		}
		return "/jsp/manage/workLogCountResult";
	}
	
	@RequestMapping(value="/exportWorkLogData.mge",method=RequestMethod.POST)
	public String exportWorkLog(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws ParseException{
		log.info("start   exportWorkLog() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//			SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");//日志时间查询
			Date firstDate = null;
			Date secondDate = null;
			String logDate_obj=null;
			//String canBeReviewUser=Config.getProperty(CANBEREVIEWUSER);
			//add by jianghaibo 2015-02-04  获取一把手日志可被审阅人列表
			 String canBeReviewUser ="";
			if("1".equals(managerVo.getLogType())||"2".equals(managerVo.getLogType())||"3".equals(managerVo.getLogType())){ //
			   canBeReviewUser = workConPowerService.findPowerUserByType(CANBEREVIEWUSER);
			}
			if(!"".equals(managerVo.getLogDate())){
				logDate_obj=managerVo.getLogDate();
			}
			
			if(!"".equals(managerVo.getStartDate())){
				firstDate = sdf.parse(managerVo.getStartDate());
			}
			if(!"".equals(managerVo.getEndDate())){
				secondDate = sdf.parse(managerVo.getEndDate());
			}
			map.put("startDate", firstDate);
			map.put("endDate", secondDate);
			map.put("empId", managerVo.getEmpId());
			map.put("emp_name", managerVo.getEmp_name());
			map.put("logDate", logDate_obj);
			map.put("logType", managerVo.getLogType());
			map.put("canBeReviewUser", canBeReviewUser);
			//map.put("countFlag", managerVo.getCountFlag());
			//List<DeptCount> list = managerService.countByDept(map);
			if(exportDataVo.getExportType().equals("excel")){
				response.setContentType("application/vnd.ms-excel");
				
				List<WorkLogCount> listExcel = null;
				
				if("1".equals(managerVo.getLogType())){ //按日志时间 查询
					map.put("postId", "A");
					listExcel= managerService.countBWorkLogBySHYForExcel(map);
				}else if("2".equals(managerVo.getLogType())){
					listExcel= managerService.countWorkLogForExcel(map);
				}
				else if("3".equals(managerVo.getLogType())){
					String marketCanBeReviewUser = workConMarketPowerService.findCanBeReviewUser();
					map.put("canBeReviewUser", marketCanBeReviewUser);
					map.put("logType", "1");
					listExcel= managerService.countWorkLogBySHYForExcel(map);
				}else if("4".equals(managerVo.getLogType())){
					map.put("postId", "B");
					listExcel= managerService.countBWorkLogBySHYForExcel(map);
				}
				System.out.println(listExcel.size());
				
				try{
					String fileName = "";
					SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
					String csysdate = sdf1.format(new Date());
					if(map.get("logDate")!=null){
						SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd");
						Date logDateD = sdf3.parse((String)map.get("logDate"));
						csysdate = sdf1.format(logDateD);
					}
					
					if(managerVo.getLogType().trim().equals("1")){
						fileName="民生保险微家A类干部日志统计"+csysdate+".xls";
					}else if(managerVo.getLogType().trim().equals("2")){
						fileName="民生保险微家营销日志统计"+csysdate+".xls";
					}else if(managerVo.getLogType().trim().equals("3")){
						fileName="民生保险微家运营管理日志统计"+csysdate+".xls";
					}else if(managerVo.getLogType().trim().equals("4")){
						fileName="民生保险微家B类经理日志统计"+csysdate+".xls";
					}else{
						fileName="民生保险微家统计.xls";
					}
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(fileName.getBytes("GBK"),"ISO-8859-1"));
				}catch(UnsupportedEncodingException e){
					e.printStackTrace();	
				}
				OutputStream out = null;
				try{
					out = response.getOutputStream();
					System.out.println(listExcel.size());
					managerService.getWorkLogExcel(map,listExcel,out);
					out.flush();
					out.close();
				}catch(IOException e){
					e.printStackTrace();
				}finally{
					try{
						if(out!=null)
							out.close();
					}catch(Exception ex){
						ex.printStackTrace();
					}
				}
				
				return "/jsp/manage/exportExcel";
			}else if(exportDataVo.getExportType().toUpperCase().equals("WORD")){
				
				OutputStream out = null;
				try{
					String fileName = "";
					SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日");
					SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
					String csysdate = "";
					String searchDate = "";
					if(map.get("logDate")!=null){
						SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd");
						Date logDateD = sdf3.parse((String)map.get("logDate"));
						csysdate = sdf1.format(logDateD);
						searchDate = sdf2.format(logDateD);
					}else{
						csysdate = sdf1.format(new Date());
						searchDate = sdf2.format(new Date());
					}
									
					SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					Date searchStartDate = sdf3.parse(searchDate+" 00:00:00");
					Date searchEndDate = sdf3.parse(searchDate+" 23:59:59");
					map.put("startDate", searchStartDate);
					map.put("endDate", searchEndDate);
					
					if(managerVo.getLogType().trim().equals("1")){
						fileName="民生保险微家A类干部工作日志统计"+csysdate+".doc";
					}else{
						fileName="民生保险微家统计.doc";
					}
					response.setContentType("application/msword");
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(fileName.getBytes("GBK"),"ISO-8859-1"));
					out = response.getOutputStream();
					
					XWPFDocument doc = new XWPFDocument();
					
					XWPFParagraph p1 = doc.createParagraph();
					p1.setAlignment(ParagraphAlignment.CENTER);
					p1.setVerticalAlignment(TextAlignment.TOP);

					XWPFRun r1 = p1.createRun();
					r1.setBold(true);
					r1.setText(csysdate+"工作日志填写情况");
					r1.setBold(true);
					r1.setFontFamily("宋体");
					r1.setTextPosition(100);
					r1.addBreak(BreakClear.ALL);
					r1.setFontSize(16);
					
					List<WorkLogCount> listExcel = null;
					if("1".equals(managerVo.getLogType())){
						map.put("postId", "A");
						listExcel= managerService.countBWorkLogBySHYForExcel(map);
					}else{
						return "/jsp/manage/error";
					}
					
					for(int flag=0;flag<listExcel.size();flag++){
						WorkLogCount workLog =  listExcel.get(flag);
						
						XWPFParagraph p2 = doc.createParagraph();
						p2.setAlignment(ParagraphAlignment.LEFT);
						
						XWPFRun r2 = p2.createRun();
						if(workLog.getWorkCon()==null){
							r2.setText("【"+workLog.getEmpName()+"】");
						}else{
							String workCon = workLog.getWorkCon();
							workCon = workCon.replace("&nbsp;", " ");
							r2.setText("【"+workLog.getEmpName()+"】"+workCon);
						}
						r2.setFontFamily("宋体");	
						r2.addBreak(BreakClear.ALL);
					}					
					doc.write(out);
					out.flush();
					out.close();
				}catch(Exception ex){
					ex.printStackTrace();
				}finally{
					try{
						if(out!=null)
							out.close();
					}catch(Exception e){
						e.printStackTrace();
					}
				}
				return "/jsp/manage/exportExcel";
			}else if(exportDataVo.getExportType().toUpperCase().equals("TXT")){
				
				OutputStream out = null;
				try{
					String fileName = "";
					SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日");
					SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
					String csysdate = "";
					String searchDate = "";
					if(map.get("logDate")!=null){
						SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd");
						Date logDateD = sdf3.parse((String)map.get("logDate"));
						csysdate = sdf1.format(logDateD);
						searchDate = sdf2.format(logDateD);
					}else{
						csysdate = sdf1.format(new Date());
						searchDate = sdf2.format(new Date());
					}
									
					SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					Date searchStartDate = sdf3.parse(searchDate+" 00:00:00");
					Date searchEndDate = sdf3.parse(searchDate+" 23:59:59");
					map.put("startDate", searchStartDate);
					map.put("endDate", searchEndDate);
					
					if(managerVo.getLogType().trim().equals("1")){
						fileName="民生保险微家A类干部工作日志统计"+csysdate+".txt";
					}else{
						fileName="民生保险微家统计.txt";
					}
					response.setContentType("text/plain");
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(fileName.getBytes("GBK"),"ISO-8859-1"));
					out = response.getOutputStream();
					
					StringBuffer sb = new StringBuffer("");
					String textTitle = csysdate+"工作日志填写情况";
					sb.append("        ").append(textTitle).append("\r\n");
	
					List<WorkLogCount> listExcel = null;
					if("1".equals(managerVo.getLogType())){
						map.put("postId", "A");
						listExcel= managerService.countBWorkLogBySHYForExcel(map);
					}else{
						return "/jsp/manage/error";
					}
					
					for(int flag=0;flag<listExcel.size();flag++){
						WorkLogCount workLog =  listExcel.get(flag);
						
						String log = "";
						if(workLog.getWorkCon()==null){
							log = "【"+workLog.getEmpName()+"】";
						}else{
							String workCon = workLog.getWorkCon();
							workCon = workCon.replace("&nbsp;", " ");
							log = "【"+workLog.getEmpName()+"】"+workCon;
						}
						sb.append(log).append("\r\n");
					}					
					out.write(sb.toString().getBytes("UTF-8"));
					out.flush();
					out.close();
				}catch(Exception ex){
					ex.printStackTrace();
				}finally{
					try{
						if(out!=null)
							out.close();
					}catch(Exception e){
						e.printStackTrace();
					}
				}
				return "/jsp/manage/exportExcel";
			}else{
//			String imageUrl = managerService.getImageUrl(list, session,request);
//			modeMap.addAttribute("imageUrl", imageUrl);
				return "/jsp/manage/exportView";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   exportWorkLog() ");
		}
		
	}
	
	@RequestMapping(value="/deptSumCount.mge",method=RequestMethod.POST)
	public String deptSumCount(ManagerVo managerVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   deptSumCount()");
		try {
			Page<User> ret;
			Map<String, Object> map = new HashMap<String, Object>();
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?10:managerBaseVo.getPageSize();
     		map.put("startDate", managerVo.getStartDate());
			map.put("endDate", managerVo.getEndDate());
			ret = managerService.countDeptSum(map, pageNo, pageSize);
			List<User> listRet = ret.getRows();
			for(int i=0;i<listRet.size();i++){
				User userRet = listRet.get(i);
				log.debug(userRet.getEmp_name());
				if(userRet.getRedFlowerNum()==null){
					userRet.setRedFlowerNum(0.0);
				}
				Double redFlowerNum = Math.floor(userRet.getRedFlowerNum());
				//Double sendFlowerNum = Math.floor(userRet.getSendFlowerNum().doubleValue());
				//Double integralNum = Math.floor(userRet.getIntegralNum().doubleValue());
				//userRet.setIntegralNum(integralNum.longValue());
				userRet.setRedFlowerNum(redFlowerNum);
				//userRet.setSendFlowerNum(sendFlowerNum.longValue());
			}
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("managerVo", managerVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   deptSumCount() ");
		}
		return "/jsp/manage/countDeptSumResult";
	}
	@RequestMapping(value="/deptSendSumCount.mge",method=RequestMethod.POST)
	public String deptSendSumCount(ManagerVo managerVo,ManagerBaseVo managerBaseVo,ModelMap modeMap) throws ParseException{
		log.info("start   deptSendSumCount()");
		try {
			Page<User> ret;
			Map<String, Object> map = new HashMap<String, Object>();
			int pageNo = managerBaseVo.getPageNo()==0?1:managerBaseVo.getPageNo();
			int pageSize = managerBaseVo.getPageSize()==0?10:managerBaseVo.getPageSize();
     		map.put("startDate", managerVo.getStartDate());
			map.put("endDate", managerVo.getEndDate());
			ret = managerService.countDeptSendSum(map, pageNo, pageSize);
			List<User> listRet = ret.getRows();
			for(int i=0;i<listRet.size();i++){
				User userRet = listRet.get(i);
				log.debug(userRet.getEmp_name());
				if(userRet.getSendFlowerNum()==null){
					userRet.setSendFlowerNum(0L);
				}
				Double sendFlowerNum = Math.floor(userRet.getSendFlowerNum().doubleValue());
				//Double integralNum = Math.floor(userRet.getIntegralNum().doubleValue());
				//userRet.setIntegralNum(integralNum.longValue());
				userRet.setSendFlowerNum(sendFlowerNum.longValue());
			}
			modeMap.addAttribute("ret", ret);
			modeMap.addAttribute("managerVo", managerVo);
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   deptSendSumCount() ");
		}
		return "/jsp/manage/countDeptSendSumResult";
	}
	@RequestMapping(value="/exportDeptRedData.mge",method=RequestMethod.POST)
	public String exportDeptRedData(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws ParseException{
		log.info("start   exportDeptRedData() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date firstDate = null;
			Date secondDate = null;
			if(!"".equals(managerVo.getStartDate())){
				firstDate = sdf.parse(managerVo.getStartDate());
			}
			if(!"".equals(managerVo.getEndDate())){
				secondDate = sdf.parse(managerVo.getEndDate());
			}
			map.put("startDate", firstDate);
			map.put("endDate", secondDate);
			if(exportDataVo.getExportType().equals("excel")){
				response.setContentType("application/vnd.ms-excel");
				List<User> listExcel = managerService.countDeptRedForExcel(map);
				for(int i=0;i<listExcel.size();i++){
					if(listExcel.get(i).getRedFlowerNum()==null){
						listExcel.get(i).setRedFlowerNum(0.0);
					}
					Double redFlowerNum = Math.floor(listExcel.get(i).getRedFlowerNum());
					listExcel.get(i).setRedFlowerNum(redFlowerNum);
				}
				try{
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(("民生保险微家统计.xls").getBytes("GBK"),"ISO-8859-1"));
				}catch(UnsupportedEncodingException e){
					e.printStackTrace();	
				}
				try{
					OutputStream out = response.getOutputStream();
					System.out.println(listExcel.size());
					managerService.getDeptRedExcel(map,listExcel,out);
					out.flush();
					out.close();
				}catch(IOException e){
					e.printStackTrace();
				}
				
				return "/jsp/manage/exportExcel";
			}else{
//			String imageUrl = managerService.getImageUrl(list, session,request);
//			modeMap.addAttribute("imageUrl", imageUrl);
				return "/jsp/manage/exportView";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   exportDeptRedData() ");
		}
		
	}
	@RequestMapping(value="/exportDeptSendData.mge",method=RequestMethod.POST)
	public String exportDeptSendData(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws ParseException{
		log.info("start   exportDeptSendData() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date firstDate = null;
			Date secondDate = null;
			if(!"".equals(managerVo.getStartDate())){
				firstDate = sdf.parse(managerVo.getStartDate());
			}
			if(!"".equals(managerVo.getEndDate())){
				secondDate = sdf.parse(managerVo.getEndDate());
			}
			map.put("startDate", firstDate);
			map.put("endDate", secondDate);
			if(exportDataVo.getExportType().equals("excel")){
				response.setContentType("application/vnd.ms-excel");
				List<User> listExcel = managerService.countDeptSendForExcel(map);
				for(int i=0;i<listExcel.size();i++){
					if(listExcel.get(i).getSendFlowerNum()==null){
						listExcel.get(i).setSendFlowerNum(0L);
					}
					Double sendFlowerNum = Math.floor(listExcel.get(i).getSendFlowerNum());
					listExcel.get(i).setSendFlowerNum(sendFlowerNum.longValue());
				}
				try{
					response.setHeader("Content-Disposition","attachment;" + "filename="+new String(("民生保险微家统计.xls").getBytes("GBK"),"ISO-8859-1"));
				}catch(UnsupportedEncodingException e){
					e.printStackTrace();	
				}
				try{
					OutputStream out = response.getOutputStream();
					System.out.println(listExcel.size());
					managerService.getDeptSendExcel(map,listExcel,out);
					out.flush();
					out.close();
				}catch(IOException e){
					e.printStackTrace();
				}
				
				return "/jsp/manage/exportExcel";
			}else{
//			String imageUrl = managerService.getImageUrl(list, session,request);
//			modeMap.addAttribute("imageUrl", imageUrl);
				return "/jsp/manage/exportView";
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   exportDeptSendData() ");
		}
		
	}
	@RequestMapping(value="/to_countByTime.mge",method=RequestMethod.GET)
	public String to_countByTime(ModelMap modeMap,HttpServletRequest request, HttpServletResponse response){
		log.info("start go to /jsp/manage/countByTime.jsp");
		return "/jsp/manage/countByTime";
	}
	@RequestMapping(value="/to_count.mge",method=RequestMethod.GET)
	public String to_count(ModelMap modeMap,HttpServletRequest request, HttpServletResponse response){
		String countFlag=request.getParameter("countFlag");
		if(StringUtils.isNullOrEmpty(countFlag)){
			modeMap.put("countFlag", countFlag);
		}
		log.info("start go to /jsp/manage/count.jsp");
		return "/jsp/manage/count";
	}
	
	@RequestMapping(value="/to_logCount.mge",method=RequestMethod.GET)
	public String to_logCount(User user,ModelMap modeMap,HttpServletRequest request, HttpServletResponse response){
		log.info("start go to /jsp/manage/logCount.jsp");
		return "/jsp/manage/logCount";
	}
	@RequestMapping(value="/to_countSendByTime.mge",method=RequestMethod.GET)
	public String to_countSendByTime(ModelMap modeMap,HttpServletRequest request, HttpServletResponse response){
		log.info("start go to /jsp/manage/countSendByTime.jsp");
		return "/jsp/manage/countSendByTime";
	}
	
	@RequestMapping(value="/to_countintegralByTime.mge",method=RequestMethod.GET)
	public String to_countIntegralByTime(ModelMap modeMap,HttpServletRequest request, HttpServletResponse response){
		log.info("start go to /jsp/manage/countIntegralByTime.jsp");
		return "/jsp/manage/countIntegralByTime";
	}
	@RequestMapping(value="/to_countProgress.mge",method=RequestMethod.GET)
	public String to_countProgressByTime(ModelMap modeMap,HttpServletRequest request, HttpServletResponse response){
		log.info("start go to /jsp/manage/countProgress.jsp");
		return "/jsp/manage/countProgress";
	}
	@RequestMapping(value="/to_reviewCount.mge",method=RequestMethod.GET)
	public String to_countReviewByTime(ModelMap modeMap,HttpServletRequest request, HttpServletResponse response){
		log.info("start go to /jsp/manage/countReview.jsp");
		return "/jsp/manage/countReview";
	}
	@RequestMapping(value="/to_complainCount.mge",method=RequestMethod.GET)
	public String to_countComplainByTime(ModelMap modeMap,HttpServletRequest request, HttpServletResponse response){
		log.info("start go to /jsp/manage/countComplain.jsp");
		return "/jsp/manage/countComplain";
	}
	@RequestMapping(value="/to_workLogCount.mge",method=RequestMethod.GET)
	public String to_countWorkLog(ModelMap modeMap,HttpServletRequest request,HttpServletResponse response){
		log.info("start go to /jsp/manage/countWorkLog.jsp");
		return "/jsp/manage/countWorkLog";
	}
	@RequestMapping(value="/to_countWorkLogByWeek.mge",method=RequestMethod.GET)
	public String to_countWorkLogByWeek(ModelMap modeMap,HttpServletRequest request,HttpServletResponse response){
		log.info("start go to /jsp/manage/countWorkLogByWeek.jsp");
		return "/jsp/manage/countWorkLogByWeek";
	}
	@RequestMapping(value="/to_workBLogCount.mge",method=RequestMethod.GET)
	public String to_countBWorkLog(ModelMap modeMap,HttpServletRequest request,HttpServletResponse response){
		log.info("start go to /jsp/manage/countWorkLog.jsp");
		return "/jsp/manage/countBWorkLog";
	}
	
	@RequestMapping(value="/to_deptSumCount.mge",method=RequestMethod.GET)
	public String to_countDeptSum(ModelMap modeMap,HttpServletRequest request,HttpServletResponse response){
		log.info("start go to /jsp/manage/countDeptSum.jsp");
		return "/jsp/manage/countDeptSum";
	}
	@RequestMapping(value="/to_deptSendSumCount.mge",method=RequestMethod.GET)
	public String to_deptSendSumCount(ModelMap modeMap,HttpServletRequest request,HttpServletResponse response){
		log.info("start go to /jsp/manage/countDeptSendSum.jsp");
		return "/jsp/manage/countDeptSendSum";
	}
	
	
	@RequestMapping(value="/searchManagerSequence.mge",method=RequestMethod.POST)
	@ResponseBody
	public Message searchManagerSequence(HttpServletRequest request,HttpServletResponse response,String postId) throws ParseException{
		log.info("start searchManagerSequence() ");
		Message message = new Message(Message.STATE_200);
		try {
			String userSoftIds = userSoftService.getAllManagerEmpId(postId);
			log.info(userSoftIds);
			message.setMsg(userSoftIds);
		} catch (Exception e) {
			e.printStackTrace();
			message.setData(Message.STATE_one);
			message.setMsg("fail");
		}finally{
			log.info("end searchManagerSequence() ");
		}
		return message;
	}
	
	
	@RequestMapping(value="/saveManagerSequence.mge",method=RequestMethod.POST)
	@ResponseBody
	public Message saveManagerSequence(HttpServletRequest request,HttpServletResponse response,String postId,String managerSequence) throws ParseException{
		log.info("start saveManagerSequence() ");
		Message message = new Message(Message.STATE_200);
		try {
			log.info(postId);
			log.info(managerSequence);
			String[] strs = managerSequence.trim().split("\\|");
			String msg = "";
			postId = postId.trim();
			userSoftService.deleteAllByPostId(postId);
			int index = 0;
			for(int i=0;i<strs.length;i++){
				log.info("i========================"+i);
				index++;
				log.info("index========================"+i);
				String managerId = strs[i].trim();
				if(managerId.contains("(")){
					managerId=managerId.substring(managerId.indexOf("(")+1,managerId.lastIndexOf(")"));
				}
				if(managerId.length()==0)
					continue;				
				User user = userService.getEmpUser(managerId);
				System.out.println(user==null);
				if(user==null){
					msg+=managerId+";";
					continue;
				}
				
				UserSoft userSoft = new UserSoft();
				userSoft.setPostId(postId);
				userSoft.setSoftId(String.valueOf(index));
				userSoft.setEmpId(managerId);

				log.info("开始插入数据"+index+":"+managerId+","+postId);
				userSoftService.add(userSoft);
			}
			if(msg.trim().length()==0){
				msg = "操作成功！";
			}else{
				msg = "这些员工非公司员工："+msg+"，所以禁止操作！";
			}
			message.setMsg(msg);
		} catch (Exception e) {
			e.printStackTrace();
			message.setData(Message.STATE_one);
			message.setMsg("fail");
		}finally{
			log.info("end saveManagerSequence() ");
		}
		return message;
	}
	
	@RequestMapping(value="/to_countWorkLogByTime.mge",method=RequestMethod.GET)
	public String to_countWorkLogByTime(ModelMap modeMap,HttpServletRequest request,HttpServletResponse response){
		log.info("start go to /jsp/manage/countWorkLogByWeek.jsp");
		return "/jsp/manage/countWorkLogByTime";
	}
	
	@RequestMapping(value="/exportWorkLogByTime.mge",method=RequestMethod.POST)
	public String exportWorkLogByTime(ExportDataVo exportDataVo,ManagerVo managerVo,ModelMap modeMap,HttpSession session,HttpServletRequest request,HttpServletResponse response) throws ParseException{
		log.info("start   exportWorkLog() ");
		try {
			Map<String,Object> map = new HashMap<String, Object>();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			
			String canBeReviewUser ="";
			if("1".equals(managerVo.getLogType())||"2".equals(managerVo.getLogType())||"3".equals(managerVo.getLogType())){ //
			   canBeReviewUser = workConPowerService.findPowerUserByType(CANBEREVIEWUSER);
			}

			if("1".equals(managerVo.getLogType())){
				map.put("postId", "A");
			}else if("4".equals(managerVo.getLogType())){
				map.put("postId", "B");
			}else{
				return "/jsp/manage/error";
			}

			map.put("logType", managerVo.getLogType());
			map.put("canBeReviewUser", canBeReviewUser);
		
			String startDateStr = managerVo.getStartDate();
			String endDateStr = managerVo.getEndDate();
			
			if(StringUtils.isNullOrEmpty(startDateStr)){
				startDateStr = sdf.format(new Date());
			}
			if(StringUtils.isNullOrEmpty(endDateStr)){
				endDateStr = sdf.format(new Date());
			}
			Date startDate = sdf.parse(startDateStr);
			Date endDate = sdf.parse(endDateStr);
			Date tempDate = startDate;
			
			int betweenDate = betweenDate(startDateStr, endDateStr);
			
			int cellIndexMax = betweenDate + 4;
			int cellIndexStart = 3;
			
			try{
				String fileName="民生保险微家统计.xls";
				SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd");
				String exportDate = sdfs.format(new Date());
				if(managerVo.getLogType().trim().equals("4")){
					
					fileName="民生保险微家B类经理统计"+exportDate+".xls";
				}else if(managerVo.getLogType().trim().equals("1")){
					
					fileName="民生保险微家A类干部统计"+exportDate+".xls";
				}
				response.setHeader("Content-Disposition","attachment;" + "filename="+new String(fileName.getBytes("GBK"),"ISO-8859-1"));
			}catch(UnsupportedEncodingException e){
				e.printStackTrace();	
			}
			OutputStream out = response.getOutputStream();
			
			// 第一步，创建一个webbook，对应一个Excel文件
			HSSFWorkbook wb = new HSSFWorkbook();
			// 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
			HSSFSheet sheet = wb.createSheet("赞赞民生日志统计表");
			// 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
			HSSFRow row = sheet.createRow((int) 0);
			// 第四步，创建单元格，并设置值表头 设置表头居中
			HSSFCellStyle style = wb.createCellStyle();
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
			
			//创建第一行
			HSSFCell cell = row.createCell(0);
			cell.setCellValue("部门及科室");
			cell.setCellStyle(style);
			cell = row.createCell(1);
			cell.setCellValue("工号");
			cell.setCellStyle(style);
			cell = row.createCell(2);
			cell.setCellValue("姓名");
			cell.setCellStyle(style);
			Calendar cal = Calendar.getInstance();
			cal.setTime(startDate);
			for(int i=3;i<cellIndexMax;i++){
				cell = row.createCell(i);
				cell.setCellValue(sdf.format(cal.getTime()));
				cal.add(Calendar.DATE, 1);
			}
			cell = row.createCell(cellIndexMax);
			cell.setCellValue("填写次数合计");
			cell.setCellStyle(style);
			
			//为了复用周统计的服务类，所以直接七天为一次查询
			//循环次数
			int cycleInt = betweenDate/7 +1;
			Calendar cal2 = Calendar.getInstance();
			cal2.setTime(startDate);
			List<WorkLogCountWeek> listExcel = null;
			boolean flag = true;
			int rowMax = 1;
			for(int i=0;i<cycleInt;i++){
				for(int j=0;j<7;j++){
					map.put("weekday"+j,(new SimpleDateFormat("yyyy-MM-dd")).format(cal2.getTime()));
					map.put("endDate", (new SimpleDateFormat("yyyy-MM-dd")).format(cal2.getTime()));	
					cal2.add(Calendar.DATE, 1);
				}
				listExcel= managerService.countBWorkLogByWeekForExcel(map);
				rowMax = listExcel.size() + 1;
				for (int z = 0; z < listExcel.size(); z++)
				{
					HSSFRow row1 = null;
					if(flag){
						row1 = sheet.createRow((int)( z + 1));
					}else{
						row1 = sheet.getRow((int)( z + 1));
					}
					WorkLogCountWeek workLog =  listExcel.get(z);
					// 第四步，创建单元格，并设置值
					if(flag){
						row1.createCell(0).setCellValue(workLog.getDeptName());
						row1.createCell(1).setCellValue(workLog.getEmpId());
						row1.createCell(2).setCellValue(workLog.getEmpName());
					}
					row1.createCell(cellIndexStart).setCellValue(workLog.getWeekday0());
					row1.createCell(cellIndexStart+1).setCellValue(workLog.getWeekday1());
					row1.createCell(cellIndexStart+2).setCellValue(workLog.getWeekday2());
					row1.createCell(cellIndexStart+3).setCellValue(workLog.getWeekday3());
					row1.createCell(cellIndexStart+4).setCellValue(workLog.getWeekday4());
					row1.createCell(cellIndexStart+5).setCellValue(workLog.getWeekday5());
					row1.createCell(cellIndexStart+6).setCellValue(workLog.getWeekday6());
				}
				cellIndexStart = cellIndexStart + 7;
				flag = false;
			}
			//统计每行的数量
			for(int i=1;i<rowMax;i++){
				int count = 0;
				HSSFRow thisRow = sheet.getRow(i);
				for(int j=3;j<cellIndexMax;j++){
					thisRow.getCell(j).setCellType(CellType.STRING);
					String value = thisRow.getCell(j).toString();
					if(value==null||value.equals("")||value.equals("0")){
						thisRow.getCell(j).setCellValue("");
					}else{
						thisRow.getCell(j).setCellValue("√");
						count++;
					}
				}
				thisRow.createCell(cellIndexMax).setCellValue(String.valueOf(count));
				//消除非统计的日期
				int currenIndex = cycleInt*7+4;
				for(int z=cellIndexMax+1;z<=currenIndex;z++){
					thisRow.createCell(z).setCellValue("");
				}
			}
			
			wb.write(out);
			out.flush();
			out.close();
				
			return "/jsp/manage/exportExcel";
		} catch (Exception e) {
			e.printStackTrace();
			return "/jsp/manage/error";
		}finally{
			log.info("end   exportWorkLog() ");
		}
	}
	
	private int betweenDate(String date1,String date2){
		long between_days = 0l;
		try{
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
	        Calendar cal = Calendar.getInstance();    
	        cal.setTime(sdf.parse(date1));    
	        long time1 = cal.getTimeInMillis();                 
	        cal.setTime(sdf.parse(date2));    
	        long time2 = cal.getTimeInMillis();         
	        between_days=(time2-time1)/(1000*3600*24); 
		}catch(Exception ex){
			ex.printStackTrace();
		}
       return Integer.parseInt(String.valueOf(between_days));
	}
}
